﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using SMSSnew.DATA;
using SMSSnew.CLASSES;

namespace SMSSnew.BIZ
{
    public class HomeBIZ
    {
        DataTable dt;
        HomeDA home;

        //handle business logic for login
        public bool login(userCLZ objUser)
        {
            home = new HomeDA();
            dt = home.login(objUser);
            int noOfRows = dt.Rows.Count;
            bool verify = false;

            if (noOfRows != 0)
            {
                verify = true;
            }

            return verify;
        }

        //handle business logic for getting user type to direct user to appropriate next web page
        public string getUserType(userCLZ objUser)
        {
            home = new HomeDA();
            string type;
            dt = home.getUserType(objUser);

            type = dt.Rows[0][0].ToString();

            return type;
        }

        //handle business logic for loading security question and answer when he click forgot the password
        public string loadSecData(userCLZ objUser, string type)
        {
            home = new HomeDA();
            string data = "";
            dt = home.getSecQues(objUser);

            if (type == "Question")
                data = dt.Rows[0][0].ToString();
            else if(type == "Answer")
                data = dt.Rows[0][1].ToString();

            return data;
        }

        //handle business logic for sending mail to user
        public bool fillAndSendMail(userCLZ objUser)
        {
            home = new HomeDA();
            bool message = false;
            mailsCLZ myMail = new mailsCLZ();
            myMail.subject = "Your Password";

            dt = home.loadReceiverMailAndPassword(objUser);

            myMail.receiverEmail = dt.Rows[0][0].ToString();
            myMail.message = dt.Rows[0][1].ToString();

            message = myMail.SendMail(myMail);
            return message;
        }

       
    }
}
